<template>
    <div>
        <div class="seach">
            <span class="seachStatus">
                {{$t('triggertime')}}
                <el-date-picker :placeholder="$t('plsset')" v-model="transTime" width="20%" type="daterange" :range-separator="$t('to')" :start-placeholder="$t('startdate')" :end-placeholder="$t('dateclosed')" format="yyyy-MM-dd" value-format="yyyy-MM-dd" size="mini"></el-date-picker>
            </span>
            <!-- <span class="seachStatus">
                {{$t('riskcontroltype')}}
                <el-select v-model="selForm.status" :placeholder="$t('plsset')" size="mini">
                    <el-option :label="'-' + $t('plsset') + '-'" :value="null"></el-option>
                    <el-option :label="$t('vlid')" value="VALID"></el-option>
                    <el-option :label="$t('invlid')" value="INVALID"></el-option>
                </el-select>
            </span> -->
            <el-button type="primary" @click="seachdataList" v-preventReClick>{{$t('qury')}}</el-button>
        </div>
        <el-card class="cardBox">
            <el-table border style="width: 100%" :data="dataTab">
                <el-table-column type="index" :label="$t('sernum')">
                </el-table-column>
                <el-table-column :prop="isEn === 1 ? 'riskRuleName' : 'riskRuleItemNameEn'" :label="$t('riskcontroltype')" width="215">
                </el-table-column>
                <el-table-column :prop="isEn === 1 ? 'riskRuleItemName' : 'riskRuleNameEn'"  :label="$t('rulename')" width="130">
                </el-table-column>
                <el-table-column prop="stopType" :label="$t('blocktype')" width="102">
                </el-table-column>
                <el-table-column prop="createTime" :label="$t('triggertime')" width="175">
                </el-table-column>
                <el-table-column prop="reqData" :label="$t('triggerparameters')" min-width="220">
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="selForm.pageNum"
                :page-sizes="[10, 15, 20, 30]"
                :page-size="selForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
import Cookies from 'js-cookie'
import {
    getriskstoplist
} from '@/libs/reqlist.js'
import { getInitDate } from '@/libs/getDate.js'
export default {
    data () {
        return {
            total: 0,
            triggeringtime: null,
            selForm: {
                endDate: null,
                orderParamIdx: 0,
                orderType: 0,
                startDate: null,
                pageNum: 1,
                pageSize: 10
            },
            dataTab: [],
            isEn: 0,
            transTime: []
        }
    },
    methods: {
        getriskrecordList () {
            getriskstoplist(JSON.stringify(this.selForm)).then(res => {
                if (res.data.code === '000000') {
                    this.total = res.data.data.total - 0
                    this.dataTab = res.data.data.list
                }
            })
        },
        handleSizeChange (newSize) {
            this.selForm.pageSize = newSize
            this.getriskrecordList()
        },
        // 监听总页数变化
        handleCurrentChange (newNum) {
            this.selForm.pageNum = newNum
            this.getriskrecordList()
        },
        seachdataList () {
            if (this.transTime !== null) {
                this.selForm.startDate = this.transTime[0] + ' 00:00:00'
                this.selForm.endDate = this.transTime[1] + ' 00:00:00'
            }
            if (!this.transTime) {
                this.transTime = []
                this.selForm.endDate = getInitDate(0, 0) + ' 00:00:00'
                this.selForm.startDate = getInitDate(7, 0) + ' 00:00:00'
                this.transTime.push(this.selForm.startDate)
                this.transTime.push(this.selForm.endDate)
            }
            this.selForm.pageNum = 1
            this.getriskrecordList()
        }
    },
    mounted () {
        this.selForm.endDate = getInitDate(0, 0) + ' 00:00:00'
        this.selForm.startDate = getInitDate(7, 0) + ' 00:00:00'
        this.transTime.push(this.selForm.startDate)
        this.transTime.push(this.selForm.endDate)
        if (Cookies.get('language') === 'zh') this.isEn = 1
        if (Cookies.get('language') === 'en') this.isEn = 0
        this.getriskrecordList()
    }
}
</script>

<style lang="less" scoped>
@import './riskrecord.less';
</style>
